package com.example.demo;

import com.example.demo.model.Student;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JSONText {
    public static void main(String[] args) throws JsonProcessingException {
        //JSON字符串转换为对象:
        String json = "{\"id\":11,\"name\":\"zhangsan\",\"age\":5}";
        ObjectMapper mapper = new ObjectMapper();

        Student student = mapper.readValue(json,Student.class);
        System.out.println(student);

        //JSON对象转换为字符串
        String s = mapper.writeValueAsString(student);
        System.out.println(s);

    }
}
